const HotService = require("../../services/admin/HotService");

const HotController = {
  addHot: async (req, res) => {
    const { title, content, category, isPublish } = req.body;
    const cover = req.file ? `/hotsuploads/${req.file.filename}` : "";
    await HotService.addHot({
      title,
      content,
      category: Number(category),
      isPublish: Number(isPublish),
      cover,
      editTime: new Date(),
    });
    res.send({
      ActionType: "OK",
    });
  },
  updateHot: async (req, res) => {
    const { _id, title, content, category, isPublish } = req.body;
    const cover = req.file ? `/hotsuploads/${req.file.filename}` : "";
    await HotService.updateHot({
      _id,
      title,
      content,
      category: Number(category),
      isPublish: Number(isPublish),
      cover,
      editTime: new Date(),
    });
    res.send({
      ActionType: "OK",
    });
  },
  getHotsList: async (req, res) => {
    const result = await HotService.getHotsList({_id:req.params.id});
    res.send({
      ActionType: "OK",
      data: result,
    });
  },
  publish: async (req,res) => {
    await HotService.publish({
      ...req.body,
      editTime: new Date()
    });
    res.send({
      ActionType: "OK"
    });
  },
  deleteHot: async (req,res)=>{
    await HotService.deleteHot({
      _id:req.params.id
    })
    res.send({
      ActionType: "OK"
    });
  }
};

module.exports = HotController;
